#ifndef COMMONMARCO
#define COMMONMARCO

#include "cpoint.h"

#include <iostream>

#define WIDTHBYTES(bits)    \
(((bits) + 31) / 32 * 4)

#define BMP_GET_HEADER(arg) \
if(sizeof(arg) !=   \
    m_pFile->read((char*)&(arg),    \
                  sizeof(arg))) \
{   \
    qWarning() << "Read file " << m_filePathName << " error";   \
    return false;   \
}


#define MAX_FILE_SIZE           10*1024*1024
#define BMP_FILE_HEADER_SIZE    14
#define BMP_INFO_HEADER_SIZE    40
#define BMP_MAX_COLOR_NUM       256
#define distant_used_for_PHT    8
#define CHARACTER_LENGTH        128
//#define Character_length        128
#define pi 3.1415926

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

#define STEP_FIND_INNER_INDEX               1
#define STEP_FIND_OUTER_INDEX               2
#define STEP_DLInsAlgorithm_INDEX           3
#define STEP_LOGBin_INDEX                   4
#define STEP_Morphological_INDEX            5
#define STEP_Get_Chara_INDEX                6
#define STEP_Save_Chara_INDEX               7   //save to db
#define STEP_Recognise_INDEX                8

typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;

typedef char*   LPSTR;


typedef struct tagPHTPoint
{
    CPoint Point;
    int LineNumber;
}PHTPoint;
typedef QList<PHTPoint> listPoint_type;

typedef struct tagCIRCLE
{
    int x;
    int y;
    int r;
}CIRCLE;

//circle
typedef struct tagPHTPointGROUP
{	CPoint a;
    CPoint b;
    CPoint c;
}PHTPointGROUP;
typedef QList<PHTPointGROUP> listPointGroup_type;

typedef struct tagPointInformation
{
    bool useful;
    long left;
    long right;
    long top;
    long bottom;
    long size;
    long xsum;
    long ysum;
}PointInformation;

typedef struct tagCharacterVector
{
    long left;
    long right;
    long top;
    long bottom;
    long type;
    long x;
    long y;
}CharacterVector;

typedef struct FileName_Chara
{
    std::string FileName;
    CharacterVector * Chara;
}FileName_Chara;

typedef struct stBITMAPFILEHEADER
{
    uint16  bfType;
    uint32  bfSize;
    uint16  bfReserved1;
    uint16  bfReserved2;
    uint32  bfOffBits;
}BITMAPFILEHEADER;

typedef struct tagBITMAPINFOHEADER
{
    uint32  biSize;
    uint32  biWidth;
    uint32  biHeight;
    uint16  biPlanes;
    uint16  biBitCount;
    uint32  biCompression;
    uint32  biSizeImage;
    uint32  biXPelsPerMeter;
    uint32  biYPelsPerMeter;
    uint32  biClrUsed;
    uint32  biClrImportant;
}BITMAPINFOHEADER;

typedef struct tagRGBQUAD
{
    uint8   rgbBlue;
    uint8   rgbGreen;
    uint8   rgbRed;
    uint8   rgbReserved;
}RGBQUAD;

inline float distance(CIRCLE a,CIRCLE b)
{
   return  sqrt((pow((double)(a.x-b.x),2)+pow((double)(a.y-b.y),2)+pow((double)(a.r-b.r),2)));
}
inline float mid(float a,float b,float  c)
{
    if(a>b&&a<c||a>c&&a<b)
          return a;
    if(a<b&&b<c||a>b&&b>c)
          return b;
    if(a<c&&b>c||a>c&&b<c)
          return c;
}

#endif // COMMONMARCO

